package com.example.pageexample.view;

import android.graphics.Rect;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * 自定义列表间距
 * @author mailangdeguozhe
 * @date 20210710
 */
public class StaggeredDecoration extends RecyclerView.ItemDecoration {
    private int mSpace;

    public StaggeredDecoration(int space) {
        mSpace = space;
    }

    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        outRect.left=mSpace;
        outRect.right=mSpace;
        outRect.bottom=mSpace;
        if(parent.getChildAdapterPosition(view)==0){
            outRect.top=mSpace;
        }
    }
}
